package com.cn.xly2023.service.impl;

import com.cn.xly2023.mapper.GoodMapper;
import com.cn.xly2023.pojo.Good;
import com.cn.xly2023.pojo.PageBean;
import com.cn.xly2023.service.GoodService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;


@Service
public class GoodServiceImpl implements GoodService {
    @Resource
    GoodMapper goodMapper;

    @Transactional
    public PageBean selectall(Integer page,Integer pageSize,String goodName,Integer deleteStatus,Integer status){
        //1.使用pageHelper插件设置分页参数
        PageHelper.startPage(page, pageSize);
        //2.查询所有的信息
        List<Good> list = goodMapper.selectList(goodName,deleteStatus,status);
        PageInfo<Good> p = new PageInfo<>(list);
        //3.封装PageBean对象
        PageBean pageBean = new PageBean(p.getTotal(), p.getList());
        return pageBean;
    }

    @Override
    public void deleteByIds(List<Integer> ids) {
        goodMapper.deleteByIds(ids);
    }

    @Override
    public void insertGood(Good good){
        goodMapper.insertGood(good);
    }

    @Override
    public void updateGood(Good good){
        goodMapper.updateGood(good);
    }


}
